import java.util.Stack;

public class test1 {
    public static void main1(String[] args) {
        MyStack m = new MyStack(10);
        m.push(4);
        m.push(3);
        m.push(2);
        m.push(1);
        System.out.println(m.pop());
        System.out.println(m.peek());
        System.out.println(m.peek());
    }
    //判断是否为数字
    public static boolean isOperation(String x) {
        if(x.equals("+") | x.equals("-") | x.equals("*") | x.equals("/")) {
            return false;
        }
        return true;
    }

    public static int evalRNP(String[] tokens) {
        Stack<String> stack = new Stack<>();
        for(String x : tokens) {
            if(!isOperation(x)) {
                //如果不是数字
                int num1 = Integer.parseInt(stack.pop()); //栈顶元素 => 放在右边
                int num2 = Integer.parseInt(stack.pop()); //栈顶后面一个元素 => 放在左边
                switch(x) {
                    case "+":
                        stack.push(String.valueOf((num2 + num1)));
                        break;
                    case "-":
                        stack.push(String.valueOf((num2 - num1)));
                        break;
                    case "*":
                        stack.push(String.valueOf((num2 * num1)));
                        break;
                    case "/":
                        stack.push(String.valueOf((num2 / num1)));
                        break;
                    default:
                        break;
                }
            }else {
                stack.push(x);
            }
        }
        return Integer.parseInt(stack.peek());
    }

    public static void main3(String[] args) {
        //求逆波兰表达式（后缀表达式）的值
        String[] tokens = new String[]{"2","1","+","3","*"};
        System.out.println(evalRNP(tokens));


    }

    public static void main4(String[] args) {
        Stack<Integer> s = new Stack<>();
        Stack<Character> stack = new Stack<>();
        s.push(1);
        s.push(1);
        System.out.println(s.pop());
        System.out.println(s.pop());
        System.out.println(s.pop());
    }

    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        char[] arr = s.toCharArray();
        for(char x : arr) {
            if(stack.empty()) {
                stack.push(x);
            }else {
                if(stack.peek() == '(' && x == ')' || stack.peek() == '[' && x == ']' || stack.peek() == '{' && x == '}') {
                    stack.pop();
                }else {
                    stack.push(x);
                }
            }
        }
        return stack.empty();
    }
    public static void main(String[] args) {
        System.out.println(isValid("{[]}}"));
    }
}
